package com.example.zhxy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhxy.model.Grade;
import com.example.zhxy.service.GradeService;
import com.example.zhxy.mapper.GradeMapper;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

/**
* @author fzykd
* @description 针对表【tb_grade】的数据库操作Service实现
* @createDate 2023-03-13 21:26:35
*/
@Service
public class GradeServiceImpl extends ServiceImpl<GradeMapper, Grade>
    implements GradeService {


    //获取全部的年级信息


    @Override
    public List<Grade> getGrades() {
        //调用baseMapper
       return baseMapper.selectList(null);
    }

    @Override
    public IPage<Grade> getGradeByOpr(Page<Grade> page1, String gradeName) {
        //设置查询条件
        QueryWrapper<Grade> queryWrapper = new QueryWrapper();
        if (!StringUtils.isEmpty(gradeName)){
            queryWrapper.like("name",gradeName);
        }
        //设置排序 ASC升序
        queryWrapper.orderByAsc("id");
        queryWrapper.orderByAsc("name");
        //分页查询数据
        Page page = baseMapper.selectPage(page1,queryWrapper);

        return page;

    }
}




